package homework.exp06;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.*;

public class C {
    static Scanner cin = null;

    static {
        try {
            cin = new Scanner(new FileInputStream(new File("src/homework/exp06/C.in")));
        } catch (IOException e) {
            cin = new Scanner(System.in);
        }
    }

    public static void main(String[] args) {
        Scanner cin = new Scanner(System.in);
        int t = cin.nextInt();

        while ((t--) != 0) {
            int n = cin.nextInt();

            List<String> strs = new ArrayList<String>();
            ArrayList<LinkedList<Integer>> map = new ArrayList<LinkedList<Integer>>();
            ArrayList<Integer> in = new ArrayList<Integer>();
            //二维链表地图
            for (int i = 0; i < n; i++) {
                String str1 = cin.next();
                String str2 = cin.next();
                int idx1 = strs.indexOf(str1);
                if (idx1 == -1) {
                    idx1 = strs.size();
                    strs.add(str1);
                }
                int idx2 = strs.indexOf(str2);
                if (idx2 == -1) {
                    idx2 = strs.size();
                    strs.add(str1);
                }
                if (map.size() - 1 < idx1) {
                    for (int j = map.size(); j <= idx1; j++) {
                        map.add(new LinkedList<Integer>());
                    }
                }
                if (map.size() - 1 < idx2) {
                    for (int j = map.size(); j <= idx2; j++) {
                        map.add(new LinkedList<Integer>());
                    }
                }
                map.get(idx1).add(idx2);
                if (in.size() - 1 < idx2) {
                    for (int j = in.size(); j <= idx2; j++) {
                        in.add(0);
                    }
                }
                in.set(idx2, in.get(idx2) + 1);
            }
//拓扑排序
            Queue<Integer> q = new LinkedList<Integer>();


            for (int i = 0; i < in.size(); i++) {
                if (in.get(i) == 0) {
                    q.offer(i);
                    for (Integer m : map.get(i)) {
                        in.set(m, in.get(m) - 1);
                    }

                }
            }
            while (!q.isEmpty()) {
                int temp = q.poll();


                for (Integer m : map.get(temp)) {
                    if (in.get(m) == 0) {
                        for (Integer k : map.get(m)) {
                            in.set(k, in.get(k) - 1);
                        }
                    }

                }

            }
            int i = 0;
            for (i = 0; i < in.size(); i++) {

                if (in.get(i) > 0) {
                    System.out.println("Failed");
                    break;
                }
            }
            if (i >= in.size()) {
                System.out.println("Passed");
            }
        }


        //TODO
        cin.close();

    }
}